package com.zb.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {
    /******************************************************************/

    public static final String ADD_COURSE_SUCCESS_EXCHANGE = "addCourseSuccessExchange";
    public static final String ADD_COURSE_SUCCESS_QUEUE = "addCourseSuccessQueue";
    public static final String ADD_COURSE_SUCCESS_ROUTING = "addCourseSuccessRouting";

    @Bean(ADD_COURSE_SUCCESS_EXCHANGE)
    public Exchange createaddCourseExchange() {
        return ExchangeBuilder.topicExchange(ADD_COURSE_SUCCESS_EXCHANGE).durable(true).build();
    }

    @Bean(ADD_COURSE_SUCCESS_QUEUE)
    public Queue createaddCourseQueue() {
        return new Queue(ADD_COURSE_SUCCESS_QUEUE, true, false, false, null);
    }

    @Bean
    public Binding bindingaddCourseExchangeAndQueue(@Qualifier(ADD_COURSE_SUCCESS_EXCHANGE) Exchange exchange, @Qualifier(ADD_COURSE_SUCCESS_QUEUE) Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(ADD_COURSE_SUCCESS_ROUTING).noargs();
    }
}
